package com.kool.system.action.errorCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kool.core.base.IBaseAction;
import com.kool.core.exception.AppException;
import com.kool.core.util.BeanUtils;
import com.kool.system.bean.SyErrorInfoBean;
import com.kool.system.bean.io.errorCode.SYERRORCODEXBean;
import com.kool.system.service.ErrorCodeService;

/**
 * @DESCRIBE 删除
 * @AUTHOR LUYU
 */
@Controller
public class DeleteErrorCodeAction implements IBaseAction {
	@Autowired
	private ErrorCodeService service;

	@Override
	@ResponseBody
	@RequestMapping(value = "/sys/errorCode/deleteErrorCode", method = RequestMethod.POST)
	public JSONObject doAction(@RequestBody String sInput) throws AppException {
		JSONObject pkgIn = JSONObject.parseObject(sInput);
		JSONArray secIn = pkgIn.getJSONArray("SYERRORCODEX");
		if (null == secIn || secIn.size() <= 0) {
			throw new AppException("SY000047");// 输入为空
		}
		JSONObject propIn = secIn.getJSONObject(0);
		SYERRORCODEXBean ioIn = JSON.toJavaObject(propIn, SYERRORCODEXBean.class);
		ioIn.validate();

		SyErrorInfoBean beanIn = (SyErrorInfoBean) BeanUtils.io2Bean(ioIn, SyErrorInfoBean.class, "sei");
		service.delete(beanIn);

		return null;
	}

}
